//
//  SMHMineHeadView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/3.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHMineHeadView: UICollectionReusableView {


    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:UI
    func setupUI() {
        
        //头像背景
        let headView = UIView()
        headView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
        self.addSubview(headView)
        headView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.width.height.equalTo(74)
            make.top.equalTo(kisPhoneX() ? 66 : 50)
        }
        headView.clipRectCorner(direction: .allCorners, cornerRadius: 74/2)
        
        let headImageView = UIImageView()
        headImageView.image = UIImage.init(named: "icon_mine_header_default")
        headView.addSubview(headImageView)
        headImageView.snp.makeConstraints { (make) in
            make.center.equalTo(headView)
            make.width.height.equalTo(70)
        }
        
        //登录注册
        let loginBtn = UIButton()
        loginBtn.setTitle("登录/注册", for: .normal)
        loginBtn.titleLabel?.font = ktextBoldFont(size: 21)
        loginBtn.setTitleColor(.white, for: .normal)
        loginBtn.contentHorizontalAlignment = .left
        addSubview(loginBtn)
        loginBtn.snp.makeConstraints { (make) in
            make.left.equalTo(headImageView.snp.right).offset(15)
            make.centerY.equalTo(headImageView.snp.centerY)
            make.right.equalTo(-50)
            make.height.equalTo(20)
        }
        
        //消息
        let noticeBtn = UIButton()
        noticeBtn.setImage(UIImage.init(named: "icon_mine_notice"), for: .normal)
        addSubview(noticeBtn)
        noticeBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.top.equalTo(headImageView)
            make.width.equalTo(25)
            make.height.equalTo(25)
        }
        
        
        //名字
//        let nameLab = UILabel()
//        nameLab.font = ktextBoldFont(size: 17)
            
        
        
        
        //等级
        
        //服务费
        
        
        //去付款
        
    

        
        //邀请
        let inviteView = SMHMineInviteView.init(viewModel: self.viewModel)
        inviteView.backgroundColor = UIColor.orange
        addSubview(inviteView)
        inviteView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(60)
            make.top.equalTo(headView.snp.bottom).offset(45)
        }
        
        //UIColorHex(0xFDE0A6),UIColorHex(0xFFEDC7)
        inviteView.layoutViewGradient(style: .ViewGradientStyleLeft, colors: [UIColorFromHex(rgbValue: 0xFFEDC7).cgColor,UIColorFromHex(rgbValue: 0xFDE0A6).cgColor])
        inviteView.clipRectCorner(direction: .allCorners, cornerRadius: 6)
        
        
        //订单
        let orderView = SMHMineOrderView.init(viewModel: self.viewModel)
        orderView.backgroundColor = UIColor.white
        addSubview(orderView)
        orderView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(115)
            make.top.equalTo(inviteView.snp.bottom).offset(10)
        }
        orderView.clipRectCorner(direction: .allCorners, cornerRadius: 6)

        
        //功能
        let toolView = SMHMineToolView.init(viewModel: self.viewModel)
        toolView.backgroundColor = UIColor.white
        addSubview(toolView)
        toolView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(385)
            make.top.equalTo(orderView.snp.bottom).offset(10)
        }
        toolView.clipRectCorner(direction: .allCorners, cornerRadius: 6)

        
        //我的商品
        let sectionView = SMHMineProductSectionView.init(frame: CGRect.zero)
        addSubview(sectionView)
        sectionView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(35)
            make.top.equalTo(toolView.snp.bottom)
        }
    
        sectionView.layoutIfNeeded()
        print("高度是 == \(sectionView.frame)")
        
    }
     
    
    
    lazy var viewModel : SMHMineViewModel = {
        let viewModel = SMHMineViewModel()
        return viewModel
    }()
}
